<?php


namespace app\websocket\controller;


use app\websocket\model\User;
use think\Controller;
use think\Request;

class Login extends Controller
{
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
    }

    /**
     * checkLogin
     * 检查token
     * @url
     * @method
     * @param string $user_name 用户名
     * @param string $token token
     * @return array|bool
     * @author Asira
     * @date 2021/1/20
     */
    public static function checkLogin($user_name, $token)
    {
        $user_data=User::getUserByName($user_name);
        if(empty($user_data)){
            return false;
        }
        $files=file_get_contents(APP_PATH.'websocket'.DIRECTORY_SEPARATOR.'json'.DIRECTORY_SEPARATOR.'user'.$user_data['id'].'.json');
        if(!empty($files)) {
            $data = json_decode($files, true);
            if ($data && in_array($token,$data['user_token'], true)) {
                return $user_data;
            }
        }
        return false;
    }

    public static function doLogin(){

    }
}